// number
let n1: number = 10
n1 = 20
console.log(n1)

function add(n1: number, n2: number) {
    const total = n1 + n2
    return total
}

console.log(add(10, 20))


// string
let Name: string = "hugo"
let PrintName = `My name is ${Name}`
let NewName = Name.toUpperCase()
console.log(PrintName, NewName)


// boolean
let isTrue: boolean
isTrue = true
console.log(isTrue)


// array
let list1: number[] = [1, 2, 3, 4]
let list2: Array<number> = [1, 2, 3, 4]
let list3 = [1,2,3,4]

let list4 = [1, 'tsc']
let list5: any[] = [1, 'python', true]

console.log(list1, list2, list3, list4, list5)


// tuple 是固定长度，固定类型,受限的数组类型; 适用于固定限制的存储方式 比如： person: [number(学号), string(姓名)] = [2207, 'hugo']
let person1: [number, string] =[1, 'hugo']
// person1[0] = 'hugo', person1[1] = 1
// person[2] = 2
person1.push(3) // 坑
console.log(person1)

let person2 = [1, 'hugo'] // 是数组而不是元组


// union
function ToStr(n1: number | string, n2: number | string){
    if (typeof n1 === "number" || typeof n2 === "string")
        return n1.toString() + n2.toString();
    return n1 + n2;
}

console.log(ToStr(2,5))

let union2: 0 | 1 | 2 // 只能设置值 0， 1， 2
// union2 = 3 // Type '3' is not assignable to type '0 | 1 | 2'
union2 = 2
console.log(union2)
